package com.ohxwj.modules.web.controller;


import com.ohxwj.modules.web.util.DateUtil;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;

public class AbstractAction {

	protected String getStringParamFromRequest(HttpServletRequest request, String key) {
		String str = request.getParameter(key);
		return str;
	}

	protected int getIntegerParamFromRequest(HttpServletRequest request, String key) {
		int i = 0;
		String str = request.getParameter(key);
		if (str != null) {
			i = Integer.parseInt(str);
		}
		return i;
	}

	protected Long getLongParamFromRequest(HttpServletRequest request, String key) {
		long i = 0;
		String str = request.getParameter(key);
		if (str != null) {
			i = Long.valueOf(str);
		}
		return i;
	}

    protected BigDecimal getDecimalParamFromRequest(HttpServletRequest request, String key) {
        BigDecimal i = new BigDecimal(0);
        String str = request.getParameter(key);
        if (str != null) {
            i = new BigDecimal(str);
        }
        return i;
    }

	protected Date getDateParamFromRequest(HttpServletRequest request, String key) {
		Date t = null;
		String str=request.getParameter(key);
		if (str!=null) {
			t= DateUtil.parseDate(str);
		}
		return t;
	}

	protected Boolean getBooleParamFromRequest(HttpServletRequest request, String key) {
		String str = request.getParameter(key);
		return Boolean.parseBoolean(str);
	}


}
